﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="editaddr.aspx.cs" Inherits="jmwqz.editaddr" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
    <title>新增收货地址</title>
    <meta charset="UTF-8">

    <meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link href="/shop/templates/default/css/style.css" rel="stylesheet" />
    <link href="/shop/templates/default/css/templates.css" rel="stylesheet" />
    <script type="text/javascript" src="/scripts/jquery/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#province').change(function () {
                updateArea("getCity", $("#city"), $('#province').val());
            })
            $('#city').change(function () {
                updateArea("getArea", $("#regionId"), $('#city').val());
            })

            updateArea("getProvince", $("#province"), 0);
            if ($("#tbaddrid").val() != "") {
                getcontent($("#tbaddrid").val());
            }
            $('#save_addr').click(function () {
                if ($("#tbaddrid").val() == "") {
                    submit("addcontent")
                }
                else { submit("editcontent") }
            })
        });
        function updateArea(myact,element,areaid) {
            $.ajax({
                type: "Post",
                async: false,
                dataType: 'json',
                url: "ajax/editaddr.ashx?myact=" + myact + "&areaid=" + areaid,
                cache: false,
                success: function (data) {
                    if (data == "1") {
                        return;
                    } else {
                        element.html("");
                        element.append("<option value='-1'>请选择</option>")
                        $.each(data.data, function (i, item) {
                            addArea(i, item, data.data, element);
                        })
                    }
                }
            });
        }
        function addArea(i, item, data,ele) {
            ele.append("<option value='"+ data[i].id +"'>"+ data[i].name +"</option>")
        }
        function validadd() {
            if ($("#name").val().length == 0) {
                return false;
            }
            if ($("#province").val() == -1) {
                return false;
            }
            if ($("#city").val().length == -1) {
                return false;
            }
            if ($("#regionId").val().length == -1) {
                return false;
            }
            if ($("#mobile").val().length == 0) {
                return false;
            }
            if ($("#address").val().length == 0) {
                return false;
            }
            return true;
        }
        function getcontent(id) {
            $.ajax({
                type: "Post",
                async: true,
                dataType: 'json',
                url: "ajax/editaddr.ashx?myact=" + "getcontent" + "&id=" + id,
                cache: false,
                success: function (data) {
                    if (data == "1") {
                        return;
                    } else {
                        $("#name").val(data["contractPerson"]);
                        $("#address").val(data["addrDetail"]);
                        $("#mobile").val(data["tel"]);
                        $("#province").val(data["province"]);
                        updateArea("getCity", $("#city"), $('#province').val());
                        $("#city").val(data["city"]);
                        updateArea("getArea", $("#regionId"), $('#city').val());
                        $("#regionId").val(data["area"]);
                    }
                }
            });
        }
        function submit(myact) {
            if (!validadd()) {
                alert("地址填写不全");
                return;
            }
            $.ajax({
                type: "Post",
                async: true,
                dataType: 'json',
                url: "ajax/editaddr.ashx?myact=" + myact + "&id=" + $("#tbaddrid").val() + "&name=" + $("#name").val() + "&pid=" + $("#province").val()
                + "&cid=" + $("#city").val()+ "&rid=" + $("#regionId").val() + "&phone=" + encodeURIComponent($("#mobile").val()) + "&address=" + encodeURIComponent($("#address").val()),
                cache: false,
                success: function (data) {
                    if (data == "1") {
                        alert("保存失败");
                        return;
                    } else {
                        window.location = "jifencenter.aspx";
                    }
                }
            });
        }
    </script>
</head>
<body>
    <input type="hidden" id="isUpdate" name="isUpdate" value="-1" />
    <input type="hidden" id="oprTip" name="oprTip" value="0" />
    <input type="hidden" id="provId" name="provId" value="-1" />

    <form method="post" action="editaddr.aspx?myact=editAddr" id="ctl00">
          <input type="hidden" value="" id="openid" name="openid">
          <input type="hidden" value="" id="wid" name="wid">
           <input type="hidden" value="" id="frompage" name="frompage">
        <div class="lay_page page_address_add" id="page_address_add">
            <div class="lay_page_wrap">
                <div class="qb_gap qb_pt10">

                    <div class="qb_mb10 qb_flex">
                        <input name="name" type="text" id="name" class="mod_input flex_box" placeholder="收件人姓名"  value="" />
                    </div>
                    <div class="qb_mb10 mod_color_strong qb_fs_s qb_none" id="name_msg"></div>
                    <div>
                        城市：
                        <span class="mod_select qb_mr10 qb_mb10" id="sprovince" data-url="/ajax/editaddr.ashx?myact=getCity">
                            <select name="pvid" id="province" runat="Server">
                                <option value="-1">请选择</option>
                            </select>
                        </span>
                        <span class="mod_select qb_mr10" id="scity" data-url="/ajax/editaddr.ashx?myact=getArea">
                            <select name="ctiy" id="city" runat="Server">
                                <option value="-1">请选择</option>

                            </select></span>
                        <span class='mod_select qb_mb10'>
                            <select name="regionId" id="regionId" runat="Server">
                                <option value="-1">请选择</option>
                            </select></span>
                    </div>
                    <div class="qb_mb10 mod_color_strong qb_fs_s qb_none" id="region_msg"></div>
                    <div class="qb_mb10 qb_flex">
                        <input name="address" type="text" id="address" class="mod_input flex_box" placeholder="详细地址" value="" />
                    </div>
                    <div class="qb_mb10 mod_color_strong qb_fs_s qb_none" id="address_msg"></div>
                    <div class="qb_mb10 qb_flex">
                        <input name="mobile" type="text" id="mobile" placeholder="联系电话" class="mod_input flex_box" value="" />
                    </div>
                    <div class="qb_mb10 mod_color_strong qb_fs_s qb_none" id="mobile_msg"></div>
                    <div class="qb_mb10">
                        <input type="button" id="save_addr" class="mod_btn btn_em btn_block" value="保存收货地址"></input>
                    </div>
                </div>
            </div>
        </div>
    </form>
      <!--_bottom-->
    <!--/_bottom-->	
     <input type="hidden" value="<%= GetAddrID() %>" id="tbaddrid">
<%--  <script src="/shop/templates/default/js/zepto.min.js"></script>--%>
</body>
</html>

